<div th:fragment="main" id="subSystem">
<link rel="stylesheet" th:href="@{/css/subSystemGroup/subSystem.css}">
<div class="subSystem-header clearfix">
	<form class="navbar-form" onsubmit="return false;">
        <div class="groups form-group">
            <span class="find">
                <i class="fa fa-search"></i>
            </span> 
            <input type="text" class="form-control search" id="search" placeholder="请输入子系统名称">
        </div>
        <input type="button" value="搜索" class="btn btn-primary nav-btn" id="searchSubSystem">
    </form>
    <a href="#platform-subSystemGroup-addSubSystem" id="addSubSystem" class="addSubSystem btn btn-primary nav-btn">新建子系统</a>
</div>
<div id="subSystemBox">
	<table id="subSystemTable"></table>
    <div id="subSystemPager"></div> 
    <!--删除提示模态框  -->
<div id="deleteNotice" class="modal fade bs-example-modal-sm notice" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h3 class="modal-title" id="myModalLabel">操作提示</h3>
            </div>
            <div class="modal-body">
                确认删除此条数据吗？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="deleteData">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        	</div>
    	</div>
   	</div>
</div>
</div>
<script th:src="@{/assets/jqGrid/js/grid.locale-cn.js}"></script>
<script th:src="@{/assets/jqGrid/js/jquery.jqGrid.src.js}"></script>
        
<script>
var parentHeight,parentWidth;
$(function(){
	parentHeight = $("#subSystemBox").height() - 55;
    parentWidth = $("#subSystemBox").width();
 	// 操作按钮
    function operation(cellvalue,options,rowObject){
        var amend = "<input style='margin:5px 3px' class='btn btn-primary btn-xs modify' type='button' value='修改'>";
        var deleted = "<input style='margin:5px 3px' class='btn btn-danger btn-xs del' type='button' value='删除' data-toggle='modal' data-target='.bs-example-modal-sm'>";
        return amend+deleted;
    }
	$("#subSystemTable").jqGrid({
		url: contextPath + "/SubSystem/querySubSystemJqg",
		datatype: "json",
		height: parentHeight,
	    width: parentWidth,
		colNames:['子系统ID','子系统名称','系统类型','操作'],
		colModel:[
			{name:'id',index:'id'},
			{name:'name',index:'name'},
			{name:'type',index:'type'},
			{name:'operation',index:'id', sortable: false,formatter: operation,align: "center"}
		],
		sortname:'id',
		sortorder:'asc',
		viewrecords: true,
		multiselect: true,
		rowNum: 20,
		rowList:[5,10,20],
		pager: '#subSystemPager'
	});
	$("#subSystemTable").jqGrid('navGrid', '#subSystemPager', {edit : false,add : false,del : false,search: false});
});

$(window).resize(function(){
	$("#subSystemTable").setGridWidth($('#subSystemBox').width());
	$("#subSystemTable").setGridHeight($('#subSystemBox').height() - 55);
});
// 侧边栏缩小时，实时的给jqgrid的宽和高赋值

//搜索
$("#searchSubSystem").on('click',function () {
    var sysName = $('#search').val();
    $("#subSystemTable").setGridParam({
         url : contextPath + "/SubSystem/querySubSystemJqg",
         postData : {
        	 queryCond:{
        		 sysName: sysName
        	 }
         },
        page: 1
    }).trigger("reloadGrid");
});
$('#search').on('keypress',function(event){  
    var theEvent = window.event || event;
    var code = theEvent.keyCode || theEvent.which;
    sysName = $('#search').val();
    if(code == 13) {
        $("#subSystemTable").setGridParam({
            url : contextPath + "/SubSystem/querySubSystemJqg",
            postData : {
                queryCond:{
                	sysName: sysName
                }
            },
            page: 1
        }).trigger("reloadGrid");
    }
});
var subSystemData = null;
/* 修改 || 删除 */
$("#subSystemTable").on('click','.modify,.del',function(){
	
	var id = $(this).parent().parent().attr('id');
    subSystemData = $("#subSystemTable").jqGrid('getRowData',id);
    delete subSystemData.operation;
    if($(this).hasClass("modify")){
   		window.location.hash = "platform-subSystemGroup-modifySubSystem";
    }else{
    	subSystemData.authorities = JSON.parse(subSystemData.authorities);
    }
});
$("#deleteData").on('click',function(){
	$.ajax({
        url:contextPath + '/SubSystem/deleteSubSystem',
        type:"delete",
        contentType:"application/json",
        dataType:"json",
        data: JSON.stringify(subSystemData),
        success:function(data){
            if(data.code == 1){
                $('#deleteNotice').modal('hide');
                toastr.success('删除成功！','删除成功');
                $("#subSystemTable").trigger("reloadGrid");
            }else{
                toastr.success('删除失败！','删除失败');
            }
        },
        error:function(data){
        	console.log(data);
            toastr.success('操作失败！','操作失败');
        }
    });
});
</script>
</div>

